<extend name="Public/base" />
<block name="content">
<div id="content">
	<div id="content-header">
		<div id="breadcrumb">
			<a class="tip-bottom" href="{:U('Index/index')}" data-original-title="首页"><i class="icon-home"></i> 首页</a>
			<a class="current" href="{$post_url}">{$meta_title}</a>
		</div>
	</div>
	<div class="container-fluid">
		<br/>
		<if condition="$activity_id eq 0">
			<span class="control-group">
				<select class="form-control" style="width:280px;" name="activity_select" id="activity_select" autocomplete="off">
					<option value=0>选择活动</option>
					<volist name="activity_list" id="vo">
						<option value='{$vo.activity_id}'>{$vo.activity_name|strip_tags}</option>
					</volist>
				</select>
			</span>
		<else/>
			<h2 class="fl">{$activity_id|getActivityName}</h2>
		</if>
		<span class="control-group fr">
			<span class="badge badge-important"> 1、只有VIP客户可以享受优惠卷特权！</span><br>
			<span class="badge badge-important"> 2、首单无法使用优惠卷！</span><br>
			<span class="badge badge-important"> 3、同一店铺只能使用一次优惠卷，并且单笔付款金额大于等于100元！</span>
		</span>
		<div class="row-fluid">
			<div class="span12">
				<div class="widget-box">
					<div class="widget-title">
						<span class="icon"> <i class="icon-align-justify"></i>
						</span>
						<h5>{$meta_title}</h5>
					</div>
					<form autocomplete="off">
					<div class="widget-content nopadding form-horizontal">
						<div class="control-group">
							<label class="control-label"><button class="btn btn-info btn-focus" type="button" >扫描用户信息</button></label>
							<div class="controls" style="padding-top:15px;">
								<input type="text" placeholder="扫描／输入手机号码" class="ui-wizard-content n-auto-next" name="customer_number" id="customer_number" maxlength="11" value="" onfocus="customer_clear()" onkeypress='enterPress("{:U('Order/customerSearch')}",event)'>
								<span class="help-block blue" id="customer_number_help" style="margin-top:10px; font-size:16px;"></span>
							</div>
							
						</div>
						<div class="control-group">
							<label class="control-label"><button class="btn btn-info btn-focus" type="button" >扫描纸质订单</button></label>
							<div class="controls" style="padding-top:15px;">
								<input type="text" placeholder="扫描／输入纸质订单" class="ui-wizard-content n-auto-next" name="order_number" id="order_number" value="" onfocus="shop_clear();" onkeypress='enterPress("{:U('Order/orderSearch')}",event)'>
								<span class="help-block blue" id="order_number_help" style="margin-top:10px; font-size:16px;"></span> 
							</div>
						</div>
						<div class="control-group">
				            	<label class="control-label">支付方式：</label>
				            	<div class="controls">
					                <label style="width:70px; float:left; margin-right:30px; line-height:30px;"><input type="radio" name="pay_type" value="2" />现金</label>
					                <label style="width:70px; float:left; margin-right:30px; line-height:30px;"><input type="radio" name="pay_type" value="1" /> POS机</label>
					                <span style="margin-left:20px; line-height:25px;" class="badge badge-warning">注意：请勾选支付方式！</span>
				            	</div>
				            </div>
				        
						<div class="control-group">
				            	<label class="control-label">优惠券：</label>
				            	<div class="controls">
				            	<label style="width:70px; float:left; margin-right:30px; line-height:30px;"><input type="radio" name="coupons_type" value="0" checked />否</label>
				                <label style="width:80px; float:left; line-height:30px;"><input type="radio" name="coupons_type" value="1" />
				                <input type="text" placeholder="优惠卷金额" class="ui-wizard-content n-auto-next" style="width:30px; text-align:center;" name="coupons_amount" value="20" readonly ></label>
				                <span style="margin-left:40px; line-height:25px;" class="badge badge-warning">注意：使用优惠卷客户勾选！</span>
			            	</div>
		            	</div>
						<div class="control-group">
							<label class="control-label">实收金额：</label>
							<div class="controls">
								<input type="text" placeholder="收款金额" class="ui-wizard-content" name="amount" value="" id="amount" onkeyup="javascript:CheckInputIntFloat(this);" onkeypress="print_submit(event)" >
								<span class="help-block blue"></span>
							</div>
						</div>
						<div class="form-actions">
							<input type="hidden" value="{$activity_id}" name="activity_id" id="activity_id">
							<input type="hidden" value="" name="customer_id" id="customer_id">
							<input type="hidden" value="" name="shop_id" id="shop_id">
							<input type="hidden" value="" name="order_id" id="order_id">
							<button class="btn btn-success" type="button" id="pay">确认订单</button><span style="margin-left:20px; line-height:20px;" class="badge badge-important">请先确认订单，再进行收款～</span>
						</div>
					</div>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
var search_id = null;
function CheckInputIntFloat(oInput){
    if('' != oInput.value.replace(/\d{1,}\.{0,1}\d{0,}/,'')){
        oInput.value = oInput.value.match(/\d{1,}\.{0,1}\d{0,}/) == null ? '' :oInput.value.match(/\d{1,}\.{0,1}\d{0,}/);
    }
}
function enterPress(url, e){
	var e = e || window.event;
	if(e.keyCode == 13){
		search_id = '#' + e.target.id + '_help';
		var search = $('#' + e.target.id).val();
		var activity_id = $('#activity_id').val();
		$.post(url, { search : search , activity_id : activity_id }, search_back, "json");
		return false;
    }
}
function shop_clear(){
	$('#order_number').select();
	$('#shop_id').val('');
	$('#order_number_help').html('');
}
function customer_clear(){
	$('#customer_number').select();
	$('#customer_id').val('');
	$('#customer_number_help').html('');
}
function print_submit(e){
	var e = e || window.event;
	if(e.keyCode == 13){
		$('#pay').trigger('click');
	}
}
function search_back(data){
	if(data.status == 1){
		var obj = data.info.info;
		var str = '';
		if(data.info.type == 2){
			//商户
			str = '商户：' + obj.merchant_name + 
				'<br />店铺：' + obj.shop_name + 
				'<br />品类：' + obj.conf_category;
			$('#shop_id').val(obj.shop_id);
			//金额焦点
			$('#amount').focus();
		}else if(data.info.type == 1){
			//用户
			str = '手机号：' + obj.phone_number + data.info.ticket;
			if(obj.customer_name){
				str += '<br />姓名：' + obj.customer_name;
			}
			$('#customer_id').val(obj.customer_id);
			//订单号焦点
			$('#order_number').focus();
		}
		$('#' + data.info.id).html(str);
	}else{
		$(search_id).html('');
		tke_alert(data.info, 'alert-error', 10000);
	}
}
$(document).ready(function(){
	//焦点用户
	$('#customer_number').focus();
	//焦点获取
	$('.btn-focus').click(function(){
		$(this).parent().parent().find('input').val('').focus();
	})
	//活动选择
	$('#activity_select').change(function(){
		var activity_id = $(this).val();
		if(activity_id > 0){
			$('input').attr('disabled', false);
			$('#activity_id').val(activity_id);
		}else{
			$('input').attr('disabled', true);
		}
	});
	//提交订单
	$("#pay").click(function(){
		//锁定登录按钮
		$('button').attr('disabled',true);
		$.post("{:U('Order/cashier')}", $('form').serialize(), call_back, "json");
		return false;
		function call_back(data){
			if(data.status == 1){
				$('#order_id').val(data.info);
				var str = $('form').serialize();
				var obj = window.open("__APP__/Order/printPay/" + str ,"_blank","toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes");
			} else {
				tke_alert(data.info, 'alert-error', 15000);
			}
			$('button').attr('disabled',false);
		}
	});
	//导航高亮
	highlight_subnav("{:U('Order/cashier')}");
});
</script>
</block>